﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using HYElectricSystemDiagram.DataStruct;
using HYElectricSystemDiagram.Properties;

namespace HYElectricSystemDiagram.FormSet
{
	public partial class FormLineSettingInOut : HYBaseForm
	{
		public FormLineSettingInOut(string title, int nIndex, ExternalCommandData m_commandData = null)
		{
			this.InitializeComponent();
			this.btnAdd.Image = Resource.GetImage("AddNew16");
			this.btnDel.Image = Resource.GetImage("delete16");
			this.Text = title;
			this.btnCurrentCase.Enabled = false;
			this.strTitle = title;
			this.blType = true;
			this.ReadAllData(null);
			this.Refesh(nIndex);
			this.blType = false;
			this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			if (m_commandData != null)
			{
				this.commandData = m_commandData;
			}
		}

		private void Refesh(int index)
		{
			if (this.strTitle.Equals("动力配电进线配置"))
			{
				this.RefreshPowerInData(index);
				return;
			}
			if (this.strTitle.Equals("动力配电出线配置"))
			{
				this.RefreshPowerOutData(index);
				return;
			}
			if (this.strTitle.Equals("住户配电进线配置"))
			{
				this.RefreshHouseDataIn(index);
				return;
			}
			this.btnAdd.Visible = true;
			this.btnDel.Visible = true;
			this.btnUp.Visible = true;
			this.btnDown.Visible = true;
			this.RefreshHouseDataOut(index);
		}

		private bool ReadAllData(string dir = null)
		{
			if (this.strTitle.Equals("动力配电进线配置"))
			{
				int count = this.lstIineIn.Count;
				this.lstIineIn.AddRange(GetXmlData.GetLineSettingInInfo(dir));
				if (count == this.lstIineIn.Count)
				{
					return false;
				}
			}
			else if (this.strTitle.Equals("动力配电出线配置"))
			{
				int count2 = this.lstlineOut.Count;
				this.lstlineOut.AddRange(GetXmlData.GetLineSettingOutInfo(dir));
				if (count2 == this.lstlineOut.Count)
				{
					return false;
				}
			}
			else if (this.strTitle.Equals("住户配电进线配置"))
			{
				int count3 = this.lstHouseIn.Count;
				this.lstHouseIn.AddRange(GetXmlData.GetLineSettingInHouseInfo(dir));
				if (count3 == this.lstHouseIn.Count)
				{
					return false;
				}
			}
			else
			{
				int count4 = this.lstHouseOut.Count;
				this.lstHouseOut.AddRange(GetXmlData.GetLineSettingOutHouseInfo(dir));
				if (count4 == this.lstHouseOut.Count)
				{
					return false;
				}
			}
			return true;
		}

		private string NumberToChinese(string numberStr)
		{
			string text = "0123456789";
			string text2 = "零一二三四五六七八九";
			char[] array = numberStr.ToCharArray();
			for (int i = 0; i < array.Length; i++)
			{
				int num = text.IndexOf(array[i]);
				if (num != -1)
				{
					array[i] = text2.ToCharArray()[num];
				}
			}
			return new string(array);
		}

		private void RefreshPowerInData(int index)
		{
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("箱体功率(kW)(单回路)", typeof(double));
			dataTable.Columns.Add("箱体功率(kW)(多回路)", typeof(double));
			dataTable.Columns.Add("负荷隔离开关", typeof(string));
			dataTable.Columns.Add("断路器", typeof(string));
			dataTable.Columns.Add("双电源转换开关", typeof(string));
			if (this.blType)
			{
				if (this.cbCase.Items.Count > 0)
				{
					this.cbCase.Items.Clear();
				}
				for (int i = 0; i < this.lstIineIn.Count; i++)
				{
					string item;
					if (i == index)
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString()) + "(当前方案)";
					}
					else
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString());
					}
					this.cbCase.Items.Add(item);
				}
				if (this.lstIineIn.Count == 0)
				{
					return;
				}
				this.cbCase.SelectedIndex = index;
			}
			foreach (LineSettingIn lineSettingIn in this.lstIineIn[index])
			{
				dataTable.Rows.Add(new object[]
				{
					lineSettingIn.dBoxPowerSingle,
					lineSettingIn.dBoxPowerMulti,
					lineSettingIn.strKGL,
					lineSettingIn.strBreaker,
					lineSettingIn.strDoubleSwich
				});
			}
			this.dataGridView1.DataSource = dataTable;
		}

		private void RefreshPowerOutData(int index)
		{
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("额定功率(kW)", typeof(double));
			dataTable.Columns.Add("CPS保护开关         ", typeof(string));
			dataTable.Columns.Add("断路器              ", typeof(string));
			dataTable.Columns.Add("接触器", typeof(string));
			dataTable.Columns.Add("热过载继电器", typeof(string));
			dataTable.Columns.Add("出线", typeof(string));
			dataTable.Columns.Add("管径", typeof(double));
			dataTable.Columns.Add("敷设方式", typeof(string));
			if (this.blType)
			{
				if (this.cbCase.Items.Count > 0)
				{
					this.cbCase.Items.Clear();
				}
				for (int i = 0; i < this.lstlineOut.Count; i++)
				{
					string item;
					if (i == index)
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString()) + "(当前方案)";
					}
					else
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString());
					}
					this.cbCase.Items.Add(item);
				}
				if (this.lstlineOut.Count == 0)
				{
					return;
				}
				this.cbCase.SelectedIndex = index;
			}
			foreach (LineSettingOut lineSettingOut in this.lstlineOut[index])
			{
				dataTable.Rows.Add(new object[]
				{
					lineSettingOut.dPowerRating,
					lineSettingOut.strCps,
					lineSettingOut.strBreaker,
					lineSettingOut.strContactor,
					lineSettingOut.strHotRelay,
					lineSettingOut.strOutLine,
					lineSettingOut.dPipeDiameter,
					lineSettingOut.strPerfunctoryWay
				});
			}
			this.dataGridView1.DataSource = dataTable;
		}

		private void RefreshHouseDataIn(int index)
		{
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("箱体功率(kW)", typeof(double));
			dataTable.Columns.Add("单/三相", typeof(string));
			dataTable.Columns.Add("断路器", typeof(string));
			dataTable.Columns.Add("自复式过欠压保护器", typeof(string));
			if (this.blType)
			{
				if (this.cbCase.Items.Count > 0)
				{
					this.cbCase.Items.Clear();
				}
				for (int i = 0; i < this.lstHouseIn.Count; i++)
				{
					string item;
					if (i == index)
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString()) + "(当前方案)";
					}
					else
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString());
					}
					this.cbCase.Items.Add(item);
				}
				if (this.lstHouseIn.Count == 0)
				{
					return;
				}
				this.cbCase.SelectedIndex = index;
			}
			foreach (LineSettingInHouse lineSettingInHouse in this.lstHouseIn[index])
			{
				dataTable.Rows.Add(new object[]
				{
					lineSettingInHouse.dBoxPower,
					lineSettingInHouse.strMonophase,
					lineSettingInHouse.strBreaker,
					lineSettingInHouse.strTutamen
				});
			}
			this.dataGridView1.DataSource = dataTable;
		}

		private void RefreshHouseDataOut(int index)
		{
			DataTable dataTable = new DataTable();
			this.dataGridView1.DataSource = dataTable;
			dataTable.Columns.Add("回路名称", typeof(string));
			dataTable.Columns.Add("断路器", typeof(string));
			dataTable.Columns.Add("回路编号", typeof(string));
			dataTable.Columns.Add("导线截面积", typeof(string));
			dataTable.Columns.Add("管径", typeof(double));
			dataTable.Columns.Add("敷设方式", typeof(string));
			dataTable.Columns.Add("读取族名称", typeof(string));
			if (this.blType)
			{
				if (this.cbCase.Items.Count > 0)
				{
					this.cbCase.Items.Clear();
				}
				for (int i = 0; i < this.lstHouseOut.Count; i++)
				{
					string item;
					if (i == index)
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString()) + "(当前方案)";
					}
					else
					{
						item = "方案" + this.NumberToChinese((i + 1).ToString());
					}
					this.cbCase.Items.Add(item);
				}
				if (this.lstHouseOut.Count == 0)
				{
					return;
				}
				this.cbCase.SelectedIndex = index;
			}
			foreach (LineSettingOutHouse lineSettingOutHouse in this.lstHouseOut[index])
			{
				dataTable.Rows.Add(new object[]
				{
					lineSettingOutHouse.strLoopName,
					lineSettingOutHouse.strBreaker,
					lineSettingOutHouse.strLoopNum,
					lineSettingOutHouse.strLineSectionalArea,
					lineSettingOutHouse.dPipeDiameter,
					lineSettingOutHouse.strPerfunctoryWay,
					lineSettingOutHouse.strReadFamilyName
				});
			}
			this.dataGridView1.DataSource = dataTable;
		}

		private void cbCase_SelectedIndexChanged(object sender, EventArgs e)
		{
			int selectedIndex = this.cbCase.SelectedIndex;
			if (!this.cbCase.Items[selectedIndex].ToString().Contains("当前方案"))
			{
				this.btnCurrentCase.Enabled = true;
			}
			else
			{
				this.btnCurrentCase.Enabled = false;
			}
			if (!this.blType)
			{
				this.dataGridView1.DataSource = null;
				this.Refesh(selectedIndex);
			}
		}

		private void btnNewCase_Click(object sender, EventArgs e)
		{
			FormNewCase formNewCase = new FormNewCase("方案" + this.NumberToChinese((this.cbCase.Items.Count + 1).ToString()), this.cbCase);
			if (formNewCase.ShowDialog() == DialogResult.OK)
			{
				this.strNewName = formNewCase.strName;
				this.cbCase.Items.Add(this.strNewName);
				this.InsertDataTable();
				this.cbCase.SelectedIndex = this.cbCase.Items.Count - 1;
			}
		}

		private void InsertDataTable()
		{
			if (this.strTitle.Equals("动力配电进线配置"))
			{
				this.GetLineIN(true);
				return;
			}
			if (this.strTitle.Equals("动力配电出线配置"))
			{
				this.GetLineOut(true);
				return;
			}
			if (this.strTitle.Equals("住户配电进线配置"))
			{
				this.GetHouseIn(true);
				return;
			}
			this.GetHouseOut(true);
		}

		private List<LineSettingIn> GetLineIN(bool bl = true)
		{
			List<LineSettingIn> result;
			try
			{
				List<LineSettingIn> list = new List<LineSettingIn>();
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					list.Add(new LineSettingIn
					{
						dBoxPowerSingle = double.Parse(this.dataGridView1[0, i].Value.ToString()),
						dBoxPowerMulti = double.Parse(this.dataGridView1[1, i].Value.ToString()),
						strKGL = this.dataGridView1[2, i].Value.ToString(),
						strBreaker = this.dataGridView1[3, i].Value.ToString(),
						strDoubleSwich = this.dataGridView1[4, i].Value.ToString()
					});
				}
				if (bl)
				{
					this.lstIineIn.Add(list);
				}
				result = list;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private List<LineSettingOut> GetLineOut(bool bl = true)
		{
			List<LineSettingOut> result;
			try
			{
				List<LineSettingOut> list = new List<LineSettingOut>();
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					list.Add(new LineSettingOut
					{
						dPowerRating = double.Parse(this.dataGridView1[0, i].Value.ToString()),
						strCps = this.dataGridView1[1, i].Value.ToString(),
						strBreaker = this.dataGridView1[2, i].Value.ToString(),
						strContactor = this.dataGridView1[3, i].Value.ToString(),
						strHotRelay = this.dataGridView1[4, i].Value.ToString(),
						strOutLine = this.dataGridView1[5, i].Value.ToString(),
						dPipeDiameter = double.Parse(this.dataGridView1[6, i].Value.ToString()),
						strPerfunctoryWay = this.dataGridView1[7, i].Value.ToString()
					});
				}
				if (bl)
				{
					this.lstlineOut.Add(list);
				}
				result = list;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private List<LineSettingInHouse> GetHouseIn(bool bl = true)
		{
			List<LineSettingInHouse> result;
			try
			{
				List<LineSettingInHouse> list = new List<LineSettingInHouse>();
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					list.Add(new LineSettingInHouse
					{
						dBoxPower = double.Parse(this.dataGridView1[0, i].Value.ToString()),
						strMonophase = this.dataGridView1[1, i].Value.ToString(),
						strBreaker = this.dataGridView1[2, i].Value.ToString(),
						strTutamen = this.dataGridView1[3, i].Value.ToString()
					});
				}
				if (bl)
				{
					this.lstHouseIn.Add(list);
				}
				result = list;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private List<LineSettingOutHouse> GetHouseOut(bool bl = true)
		{
			List<LineSettingOutHouse> result;
			try
			{
				List<LineSettingOutHouse> list = new List<LineSettingOutHouse>();
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					list.Add(new LineSettingOutHouse
					{
						strLoopName = this.dataGridView1[0, i].Value.ToString(),
						strBreaker = this.dataGridView1[1, i].Value.ToString(),
						strLoopNum = this.dataGridView1[2, i].Value.ToString(),
						strLineSectionalArea = this.dataGridView1[3, i].Value.ToString(),
						dPipeDiameter = double.Parse(this.dataGridView1[4, i].Value.ToString()),
						strPerfunctoryWay = this.dataGridView1[5, i].Value.ToString(),
						strReadFamilyName = this.dataGridView1[6, i].Value.ToString()
					});
				}
				if (bl)
				{
					this.lstHouseOut.Add(list);
				}
				result = list;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private void btnIn_Click(object sender, EventArgs e)
		{
			int count = this.cbCase.Items.Count;
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.InitialDirectory = "c:\\";
			openFileDialog.Filter = "Xml文件|*.xml|所有文件|*.*";
			openFileDialog.RestoreDirectory = true;
			openFileDialog.FilterIndex = 1;
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				string dir = openFileDialog.FileNames[0];
				this.blType = true;
				bool flag = this.ReadAllData(dir);
				this.Refesh(0);
				this.blType = false;
				if (!flag)
				{
					YJKMessageBox.Show("Xml格式不符合要求！");
					return;
				}
				int count2 = this.cbCase.Items.Count;
				YJKMessageBox.Show("成功导入" + (count2 - count).ToString() + "个方案！");
			}
		}

		private void btnOut_Click(object sender, EventArgs e)
		{
			if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
			{
				string text = this.folderBrowserDialog1.SelectedPath;
				text += "\\SystemGraphInfo.xml";
				if (text.Contains("\\\\"))
				{
					text = text.Replace("\\\\", "\\");
				}
				if (text.Contains("SystemGraphInfo"))
				{
					text = text.Replace("SystemGraphInfo", this.strTitle);
				}
				if (File.Exists(text))
				{
					File.Delete(text);
				}
				GetXmlData.WriteXml(text, this.lstIineIn, this.lstlineOut, this.lstHouseIn, this.lstHouseOut, false);
				YJKMessageBox.Show("导出成功\n\r导入路径为:" + text);
			}
		}

		private void btnSubmit_Click(object sender, EventArgs e)
		{
			this.DataGridViewData();
			string text = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
			if (!File.Exists(text))
			{
				string text2 = "SystemGraphSet.xml";
				string sourceFileName = AssistFunc.GetAppRootPath() + "\\Data\\ElectricalData\\" + text2;
				string destFileName = Product.WorkingLocation + text2;
				File.Copy(sourceFileName, destFileName);
			}
			GetXmlData.WriteXml(text, this.lstIineIn, this.lstlineOut, this.lstHouseIn, this.lstHouseOut, true);
			this.WriteHistory();
			YJKMessageBox.Show("应用到配置文件！");
		}

		private void WriteHistory()
		{
			int num = 0;
			for (int i = 0; i < this.cbCase.Items.Count; i++)
			{
				if (this.cbCase.Items[i].ToString().Contains("当前方案"))
				{
					num = i;
					break;
				}
			}
			if (this.strTitle.Contains("进线"))
			{
				GetXmlData.UpdateUserData(num, 0, true, this.strTitle);
				return;
			}
			GetXmlData.UpdateUserData(0, num, false, this.strTitle);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.DataGridViewData();
			string text = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
			if (!File.Exists(text))
			{
				string text2 = "SystemGraphSet.xml";
				string sourceFileName = AssistFunc.GetAppRootPath() + "\\Data\\ElectricalData\\" + text2;
				string destFileName = Product.WorkingLocation + text2;
				File.Copy(sourceFileName, destFileName);
			}
			GetXmlData.WriteXml(text, this.lstIineIn, this.lstlineOut, this.lstHouseIn, this.lstHouseOut, true);
			this.WriteHistory();
			for (int i = 0; i < this.cbCase.Items.Count; i++)
			{
				if (this.cbCase.Items[i].ToString().Contains("当前方案"))
				{
					this.nSelectIndex = i;
					break;
				}
			}
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void btnCurrentCase_Click(object sender, EventArgs e)
		{
			int selectedIndex = this.cbCase.SelectedIndex;
			this.blType = true;
			this.cbCase.Items.Clear();
			int num;
			if (this.strTitle.Equals("动力配电进线配置"))
			{
				num = this.lstIineIn.Count;
			}
			else if (this.strTitle.Equals("动力配电出线配置"))
			{
				num = this.lstlineOut.Count<List<LineSettingOut>>();
			}
			else if (this.strTitle.Equals("住户配电进线配置"))
			{
				num = this.lstHouseIn.Count<List<LineSettingInHouse>>();
			}
			else
			{
				num = this.lstHouseOut.Count<List<LineSettingOutHouse>>();
			}
			for (int i = 0; i < num; i++)
			{
				string item;
				if (i == selectedIndex)
				{
					item = "方案" + this.NumberToChinese((i + 1).ToString()) + "(当前方案)";
				}
				else
				{
					item = "方案" + this.NumberToChinese((i + 1).ToString());
				}
				this.cbCase.Items.Add(item);
			}
			this.blType = false;
			this.cbCase.SelectedIndex = selectedIndex;
			this.btnCurrentCase.Enabled = false;
		}

		private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if (this.strTitle.Equals("住户配电出线配置"))
			{
				int columnIndex = this.dataGridView1.CurrentCell.ColumnIndex;
				int index = this.dataGridView1.CurrentRow.Index;
				if (columnIndex == 6)
				{
					this.dataGridView1.ReadOnly = false;
					this.dataGridView1.Columns[0].ReadOnly = true;
					this.dataGridView1.Columns[1].ReadOnly = true;
					this.dataGridView1.Columns[2].ReadOnly = true;
					this.dataGridView1.Columns[3].ReadOnly = true;
					this.dataGridView1.Columns[4].ReadOnly = true;
					this.dataGridView1.Columns[5].ReadOnly = true;
					this.dataGridView1.Columns[6].ReadOnly = false;
				}
			}
		}

		private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			int selectedIndex = this.cbCase.SelectedIndex;
			if (this.strTitle.Equals("住户配电出线配置"))
			{
				this.lstHouseOut.RemoveAt(selectedIndex);
				this.GetHouseOut(true);
			}
		}

		private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			int selectedIndex = this.cbCase.SelectedIndex;
			if (this.strTitle.Equals("动力配电进线配置"))
			{
				List<LineSettingIn> lineIN = this.GetLineIN(false);
				if (lineIN != null)
				{
					this.lstIineIn[selectedIndex] = lineIN;
					return;
				}
			}
			else if (this.strTitle.Equals("动力配电出线配置"))
			{
				List<LineSettingOut> lineOut = this.GetLineOut(false);
				if (lineOut != null)
				{
					this.lstlineOut[selectedIndex] = lineOut;
					return;
				}
			}
			else if (this.strTitle.Equals("住户配电进线配置"))
			{
				List<LineSettingInHouse> houseIn = this.GetHouseIn(false);
				if (houseIn != null)
				{
					this.lstHouseIn[selectedIndex] = houseIn;
					return;
				}
			}
			else
			{
				List<LineSettingOutHouse> houseOut = this.GetHouseOut(false);
				if (houseOut != null)
				{
					this.lstHouseOut[selectedIndex] = houseOut;
				}
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			this.dataGridView1[0, this.dataGridView1.Rows.Count - 1].ReadOnly = false;
			string text = this.dataGridView1[0, this.dataGridView1.Rows.Count - 1].Value.ToString();
			try
			{
				if (text.Equals("新回路"))
				{
					YJKMessageBox.Show("请修改完毕后添加！");
					return;
				}
			}
			catch
			{
				return;
			}
			DataTable dataTable = (DataTable)this.dataGridView1.DataSource;
			DataRow dataRow = dataTable.NewRow();
			dataRow[0] = "新回路";
			dataRow[1] = "";
			dataRow[2] = "";
			dataRow[3] = "";
			dataRow[4] = 20;
			dataRow[5] = "";
			dataRow[6] = "";
			int count = dataTable.Rows.Count;
			dataTable.Rows.InsertAt(dataRow, count);
			this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
		}

		private void btnDel_Click(object sender, EventArgs e)
		{
			if (DialogResult.Yes == MessageBox.Show("是否删除选中的数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
			{
				if (this.dataGridView1.Rows.Count == 1)
				{
					YJKMessageBox.Show("不能删除最后一行! ");
					return;
				}
				DataGridViewRow currentRow = this.dataGridView1.CurrentRow;
				this.dataGridView1.Rows.Remove(currentRow);
				int selectedIndex = this.cbCase.SelectedIndex;
				List<LineSettingOutHouse> houseOut = this.GetHouseOut(false);
				if (houseOut != null)
				{
					this.lstHouseOut[selectedIndex] = houseOut;
				}
			}
		}

		private void btnUp_Click(object sender, EventArgs e)
		{
			int rowIndex = this.dataGridView1.CurrentCell.RowIndex;
			DataTable dataTable = (DataTable)this.dataGridView1.DataSource;
			if (rowIndex >= 1)
			{
				DataRow dataRow = dataTable.NewRow();
				dataRow[0] = this.dataGridView1[0, rowIndex].Value.ToString();
				dataRow[1] = this.dataGridView1[1, rowIndex].Value.ToString();
				dataRow[2] = this.dataGridView1[2, rowIndex].Value.ToString();
				dataRow[3] = this.dataGridView1[3, rowIndex].Value.ToString();
				dataRow[4] = double.Parse(this.dataGridView1[4, rowIndex].Value.ToString());
				dataRow[5] = this.dataGridView1[5, rowIndex].Value.ToString();
				dataRow[6] = this.dataGridView1[6, rowIndex].Value.ToString();
				this.dataGridView1[0, rowIndex].Value.ToString();
				this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[rowIndex]);
				dataTable.Rows.InsertAt(dataRow, rowIndex - 1);
				this.dataGridView1.ClearSelection();
				this.dataGridView1[0, rowIndex - 1].Selected = true;
				this.dataGridView1.CurrentCell = this.dataGridView1.Rows[rowIndex - 1].Cells[0];
				int selectedIndex = this.cbCase.SelectedIndex;
				List<LineSettingOutHouse> houseOut = this.GetHouseOut(false);
				if (houseOut != null)
				{
					this.lstHouseOut[selectedIndex] = houseOut;
				}
			}
		}

		private void btnDown_Click(object sender, EventArgs e)
		{
			int rowIndex = this.dataGridView1.CurrentCell.RowIndex;
			DataTable dataTable = (DataTable)this.dataGridView1.DataSource;
			if (rowIndex < this.dataGridView1.Rows.Count - 1)
			{
				DataRow dataRow = dataTable.NewRow();
				dataRow[0] = this.dataGridView1[0, rowIndex].Value.ToString();
				dataRow[1] = this.dataGridView1[1, rowIndex].Value.ToString();
				dataRow[2] = this.dataGridView1[2, rowIndex].Value.ToString();
				dataRow[3] = this.dataGridView1[3, rowIndex].Value.ToString();
				dataRow[4] = double.Parse(this.dataGridView1[4, rowIndex].Value.ToString());
				dataRow[5] = this.dataGridView1[5, rowIndex].Value.ToString();
				dataRow[6] = this.dataGridView1[6, rowIndex].Value.ToString();
				this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[rowIndex]);
				dataTable.Rows.InsertAt(dataRow, rowIndex + 1);
				this.dataGridView1.ClearSelection();
				this.dataGridView1[0, rowIndex + 1].Selected = true;
				this.dataGridView1.CurrentCell = this.dataGridView1.Rows[rowIndex + 1].Cells[0];
				int selectedIndex = this.cbCase.SelectedIndex;
				List<LineSettingOutHouse> houseOut = this.GetHouseOut(false);
				if (houseOut != null)
				{
					this.lstHouseOut[selectedIndex] = houseOut;
				}
			}
		}

		private void DataGridViewData()
		{
			try
			{
				if (this.strTitle.Equals("住户配电出线配置"))
				{
					string value = this.dataGridView1[0, this.dataGridView1.RowCount - 1].Value.ToString();
					string value2 = this.dataGridView1[1, this.dataGridView1.RowCount - 1].Value.ToString();
					string value3 = this.dataGridView1[2, this.dataGridView1.RowCount - 1].Value.ToString();
					string value4 = this.dataGridView1[3, this.dataGridView1.RowCount - 1].Value.ToString();
					double num = double.Parse(this.dataGridView1[4, this.dataGridView1.RowCount - 1].Value.ToString());
					string value5 = this.dataGridView1[5, this.dataGridView1.RowCount - 1].Value.ToString();
					string value6 = this.dataGridView1[6, this.dataGridView1.RowCount - 1].Value.ToString();
					if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value2) || string.IsNullOrEmpty(value3) || string.IsNullOrEmpty(value4) || string.IsNullOrEmpty(value5) || string.IsNullOrEmpty(value6) || num <= 0.0)
					{
						YJKMessageBox.Show("参数错误，请修改表格内容!");
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("参数错误，请修改表格内容!");
			}
		}

		private string strTitle = "";

		private bool blType = true;

		private string strNewName;

		private List<List<LineSettingIn>> lstIineIn = new List<List<LineSettingIn>>();

		private List<List<LineSettingOut>> lstlineOut = new List<List<LineSettingOut>>();

		private List<List<LineSettingInHouse>> lstHouseIn = new List<List<LineSettingInHouse>>();

		private List<List<LineSettingOutHouse>> lstHouseOut = new List<List<LineSettingOutHouse>>();

		private ExternalCommandData commandData;

		public int nSelectIndex;
	}
}
